<?php
	defined('_JEXEC') or die('Restricted access');
	$model = $this->data['model'];
	$search = $this->data['search'];
	$motorlist = $search['result'];
	$motorlist_count = $search['count'];

	$lim	= JRequest::getVar('limit', 25, '', 'int');
	$lim0	= JRequest::getVar('limitstart', 0, '', 'int');
	if ($lim0 > $search['count']){ $lim0 = 0; }
	jimport('joomla.html.pagination');
	$pageNav = new JPagination( $motorlist_count, $lim0, $lim );

?>
<h1>База данных по моторам</h1>
<h2>Список моторов<?= $search['count'] and $search_data['filtr'] ? ' (отобрано '.$search['count'].' шт)' : '' ?></h2>
<div class="rcbase_content">
	<div style="text-align:right;">
		<a href="/?option=com_rcbase&view=motorlist&task=search">Подбор ВМГ</a>
		| <a href="/?option=com_rcbase&view=motor&task=addmotor">Добавить новый</a>
	</div>
	<form action="/?option=com_rcbase&view=motorlist&task=search" method="get" enctype="multipart/form-data">
		<input type="hidden" name="option" value="com_rcbase"/>
		<input type="hidden" name="view" value="motorlist"/>
		<input type="hidden" name="limit" value="25"/>
		<table class="table">
			<tr>
				<th><input name='title' value="<?= $search['param']['title'] ?>" size="50" maxlength="100"/></th>
				<th><input name='kv' value="<?= $search['param']['kv'] ?>" size="10" maxlength="10"/></th>
				<th><input name='weight' value="<?= $search['param']['weight'] ?>" size="5" maxlength="8"/></th>
				<th><input name='max_current' value="<?= $search['param']['max_current'] ?>" size="5" maxlength="8"/></th>
				<th><input name='max_voltage' value="<?= $search['param']['max_voltage'] ?>" size="5" maxlength="8"/></th>
				<th><input type="submit" name="motor_filtr" value="Поиск"/></th>
			</tr>
			<tr>
				<th>Мотор</th>
				<th>KV</th>
				<th>Вес, г.</th>
				<th>Ток, А</th>
				<th>Напр., В</th>
				<!--th>Инфо</th-->
				<th>Рейтинг</th>
			</tr>
			<?php if (is_array($motorlist) and count($motorlist)): ?>
				<?php foreach ($motorlist as $row): ?>
					<tr>
						<td>
							<a href="/?option=com_rcbase&view=motor&task=motor&id=<?= $row['id'] ?>">
								<?= $row['title'] ? $row['title'] : 'Без названия' ?>
							</a>
						</td>
						<td align="right"><?= $row['kv'] ? $row['kv'] : '&nbsp;' ?></td>
						<td align="right"><?= $row['weight'] ? $row['weight'] : '&nbsp;' ?></td>
						<td align="right"><?= $row['max_current'] ? $row['max_current'] : '&nbsp;' ?></td>
						<td align="right"><?= $row['max_voltage'] ? $row['max_voltage'] : '&nbsp;' ?></td>
						<!--td><?= $row['product_id'] ?></td-->
						<td align="right">
							<span style="color:green;">
								+<?= $row['rate_up'] ? count(explode('|', $row['rate_up'])) : '0' ?>
							</span>
							/
							<span style="color:red;">
								-<?= $row['rate_down'] ? count(explode('|', $row['rate_down'])) : '0' ?>
							</span>
						</td>
					</tr>
				<?php endforeach; ?>
			<?php else: ?>
				<tr>
					<td colspan="6" align="center">По заданным параметрам ничего не найдено!</td>
				</tr>
			<?php endif; ?>
		</table>
		<div><?= $pageNav->getPagesLinks(); ?></div>
		<input type="hidden" name="limitstart" value="0" />
	</form>
</div>
